package com.ruoyi.web.controller.buy;

import com.ruoyi.buy.domain.entity.PO.BuyRequestbuyBillItem;
import com.ruoyi.buy.service.IBuyRequestbuyBillItemService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 请购单明细Controller
 * 
 * @author ruoyi
 * @date 2024-06-13
 */
@RestController
@RequestMapping("/buy/buyRequestbuyBillItem")
public class BuyRequestbuyBillItemController extends BaseController
{
    @Autowired
    private IBuyRequestbuyBillItemService buyRequestbuyBillItemService;

    /**
     * 查询请购单明细列表
     */

    @GetMapping("/list")
    public TableDataInfo list(BuyRequestbuyBillItem buyRequestbuyBillItem)
    {
        startPage();
        List<BuyRequestbuyBillItem> list = buyRequestbuyBillItemService.selectBuyRequestbuyBillItemList(buyRequestbuyBillItem);
        return getDataTable(list);
    }

    /**
     * 导出请购单明细列表
     */

    @Log(title = "请购单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyRequestbuyBillItem buyRequestbuyBillItem)
    {
        List<BuyRequestbuyBillItem> list = buyRequestbuyBillItemService.selectBuyRequestbuyBillItemList(buyRequestbuyBillItem);
        ExcelUtil<BuyRequestbuyBillItem> util = new ExcelUtil<BuyRequestbuyBillItem>(BuyRequestbuyBillItem.class);
        util.exportExcel(response, list, "请购单明细数据");
    }

    /**
     * 获取请购单明细详细信息
     */

    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(buyRequestbuyBillItemService.selectBuyRequestbuyBillItemById(id));
    }

    /**
     * 新增请购单明细
     */

    @Log(title = "请购单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BuyRequestbuyBillItem buyRequestbuyBillItem)
    {
        return toAjax(buyRequestbuyBillItemService.insertBuyRequestbuyBillItem(buyRequestbuyBillItem));
    }

    /**
     * 修改请购单明细
     */

    @Log(title = "请购单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BuyRequestbuyBillItem buyRequestbuyBillItem)
    {
        return toAjax(buyRequestbuyBillItemService.updateBuyRequestbuyBillItem(buyRequestbuyBillItem));
    }

    /**
     * 删除请购单明细
     */

    @Log(title = "请购单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(buyRequestbuyBillItemService.deleteBuyRequestbuyBillItemByIds(ids));
    }
}
